<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
    <head>
        <title>NMCEX</title>
        <link rel="shortcut icon" href="../favicon.ico" /> 
        <link rel="stylesheet" type="text/css" href="css/popup_css.css" />
        <link rel="stylesheet" type="text/css" href="css/demo.css" />
        <link rel="stylesheet" type="text/css" href="css/style5.css" />
        <link rel="stylesheet" type="text/css" href="css/css/easyui.css" />
        <link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css' />
	   <script src="js/shortcuts.js" type="text/javascript" language="javascript"></script>  
        <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js">    </script>
		<script src="js/assets/jquery/jquery-1.10.2.min.js"></script>
		<script src="js/assets/bootstrap/js/bootstrap.min.js"></script>
		<script src="js/assets/prettify/run_prettify.js"></script>
		<script src="js/assets/number-updown/js/updown.js"></script>
		<script src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
	<script src="js/stomp.js"></script>
	<script type="text/javascript" src="js/buySellProfitCalc.js"></script>
		
<style type="text/css">
			  tbody tr:hover td { background-color: #000; color :#FFF}
</style> 
	

 </head>

    <body onload="displayunicode(event); this.select();">
  
  <!--  Is an Ajax popup-->
	<div id="blanket" class="overlay" style="display:none;"></div>
		<div id="popUpDiv" style="display:none; width:757px; left:-106px; top:131px; cursor:pointer; font-family: Helvetica, sans-serif; ">
			<div style="color:#000;">
         		
                <div id="login">
				<h2><span class="fontawesome-lock"></span>Buy Window</h2>
				  
		<form name="form1" id="orderForm" method="post" action="./buy">
		<fieldset>
		  <p>
        <select id="orderType">
  		<option value="BUY">Buy</option>
 		</select>
        
        <label for="X" class="label-margin">X</label>
				<select>
				<option>NMCEX</option>
				</select>
                 <label for="TYPE" class="label-margin">TYPE</label>
				<select onchange="oncheck();" id="otype" name="otype">
                <option>RL</option>
                <option >SL</option>
                </select>
                <input type="hidden" name="cashlimit" id="cashlimit"/>
                <input type="hidden" name="marginlimit" id="marginlimit"/>
                <input type="hidden" name="marginb" id="marginb"/>
                <input type="hidden" name="accno" id="accno"/>
                
                <input type="hidden" name="accnoX" id="accnoX"/>
                <input type="hidden" name="cashX" id="cashX"/>
                <input type="hidden" name="marginX" id="marginX"/>
                <input type="hidden" name="marginbX" id="marginbX"/>
                
                <input type="hidden" name="cashl" id="cashl"/>
                <input type="hidden" name="marginl" id="marginl"/>
                <input type="hidden" name="marginb1" id="marginb1"/>
                <input type="hidden" name="accnum" id="accnum"/>
                <label for="Product Type" class="label-margin">Product Type</label>
				<select id="ptype" name="ptype"><option>Intra</option>
				<option>CarryForward</option>
				</select> 
              
                  <label for="Broker" class="label-margin">Broker</label>
				<select id="brokerId" name="brokerId">
                <option></option>
                </select>
                <label for="Username" class="label-margin">Username</label>
				<select id="userId" name="userId">
                <option></option>
                </select>
                </p>
                <div class="source-code" style="display:none;">    </div>
                 <div class="demo" style="margin-bottom:10px;">
               <p><label for="nstr. Name">Instr. Name</label>
				<input type="text" value="206803" readonly="readonly" size="10" id="insname" name="insname"></input>
                <label for="TotalQty" class="label-margin">TotalQty</label>
                <input type="text" value="6" readonly="readonly" size="5" id="qt" name="qt" style="margin-left:11px;"></input>
                <label for="TotalQty" class="label-margin">TotalLot</label>
                <input type="text" class="form-control demo-input" id="ql" name="ql" value="1" /></p></div>
                
                <p> 
                <label for="TotalQty">TotalWt</label>
                <input type="text" value="2" readonly="readonly" size="10" id="qw" name="qw" style="margin-left:22px;"></input>  
                 <label for="Trig. Price" class="label-margin">Trig. Price</label>
				<input type="text"  value="555" size="10" id="tp" name="tp" disabled /> 
                 <label for="Symbol" class="label-margin">Symbol</label>
				<input type="text" id="symbol" readonly="readonly" /></p>
                
                <p>
				<label for="Series/Expiry">Expiry Date</label>
				<input type="text" id="expdate" readonly="readonly" />
         
                <label for="Bid Rate" class="label-margin">Price</label>
				<input type="text" id="price" readonly="readonly" style="margin-left:27px;" />
               <label for="Status" class="label-margin">Status</label>
				<input type="text" id="status"  readonly="readonly" value="Executed" style="margin-left:8px;" /></p>
               
   				<input type="button" id="submit" value="Save" onclick="Close();"/>
			</fieldset>
		</form>
	</div>  
            </div>
     <a class="close" href="#close" onclick="Close();"></a>
	</div>
   <div id="blanket2" class="overlay" style="display:none;"></div>
		<div id="popUpDiv2" style="display:none; width:757px; top:131px; left:-106px; cursor:pointer; font-family: Helvetica, sans-serif; ">
			<div style="color:#000;">
         		
                <div id="login">
				<h2><span class="fontawesome-lock"></span>Sell Window</h2>
	
				<form name="form2" id="orderForm" method="post" action="./sell">
		<fieldset>
		<p>
        <select id="orderType">
  		<option value="SELL">Sell</option>
 		</select>
        <label for="X" class="label-margin">X</label>
				<select>
				<option>NMCEX</option>
				</select>
                 <label for="TYPE" class="label-margin">TYPE</label>
				<select onchange="onCheck();" id="otype1" name="otype1">
                <option>RL</option>
                <option >SL</option>
                </select>
                <input type="hidden" name="cashX1" id="cashX1"/>
                <input type="hidden" name="marginX1" id="marginX1"/>
                <input type="hidden" name="marginbX1" id="marginbX1"/>
                <input type="hidden" name="accnoX1" id="accnoX1"/>
                
                 <input type="hidden" name="cashl2" id="cashl2"/>
                <input type="hidden" name="marginl2" id="marginl2"/>
                <input type="hidden" name="accnum2" id="accnum2"/>
                <input type="hidden" name="marginb2" id="marginb2"/>
                
                <input type="hidden" name="cashl1" id="cashl1"/>
                <input type="hidden" name="marginl1" id="marginl1"/>
                <input type="hidden" name="accno1" id="accno1"/>
                <input type="hidden" name="marginb3" id="marginb3"/>
                <label for="Product Type" class="label-margin">Product Type</label>
				<select id="ptype1" name="ptype1"><option>Intra</option>
				<option>CarryForward</option>
				</select> 
             
                <label for="Broker" class="label-margin">Broker</label>
				<select id="brokerId1" name="brokerId1">
                <option></option>
                </select>
                <label for="Username" class="label-margin">Username</label>
				<select id="userId1" name="userId1">
				<option></option>
                </select>
                 </p>
              <div class="source-code" style="display:none;">    </div>
                <div class="demo" style="margin-bottom:10px;">
                <p><label for="nstr. Name">Instr. Name</label>
				<input type="text" value="206803" readonly="readonly" size="10" id="sinsname" name="sinsname"></input>
                <label for="TotalQty" class="label-margin">TotalQty</label>
                <input type="text" value="6" readonly="readonly" size="5" id="qt" name="qt" style="margin-left:11px;"></input>
                <label for="TotalQty" class="label-margin">TotalLot</label>
                <input type="text" class="form-control demo-input" id="ql1" name="ql1" value="1" /></p></div>
                <p> 
                <label for="TotalQty">TotalWt</label>
                <input type="text" value="2" readonly="readonly" size="10" id="qw" name="qw" style="margin-left:22px;"></input>  
                 <label for="Trig. Price" class="label-margin">Trig. Price</label>
				<input type="text"  value="555" size="10" id="tp" name="tp" disabled /> 
                 <label for="Symbol" class="label-margin">Symbol</label>
				<input type="text" id="ssymbol" readonly="readonly" /></p>
                
                <p>
				<label for="Series/Expiry">Expiry Date</label>
				<input type="text" id="sexpdate" readonly="readonly" />
         
                <label for="Bid Rate" class="label-margin">Price</label>
				<input type="text" id="sprice" readonly="readonly" style="margin-left:27px;" />
               <label for="Status" class="label-margin">Status</label>
				<input type="text" id="status1"  readonly="readonly" value="Executed" style="margin-left:8px;" /></p>
                
   				<input type="button" id="save" value="Save" onclick="Close();"/>
			</fieldset>
		</form>	</div>  
            </div>
     <a class="close" href="#close" onclick="Close();"></a>
	</div>	 
        <div class="container">
            <div class="header">
               <strong>Back to the Codrops Article</strong></a>-->
                <!--</span>-->
                <div class="top-header">
                <nav>
            <ul class="fancyNav">
                <li id="home"><a href="index"><span class="a-btn-symbol"><img src="images/home-icon.png" style="width:27px; height:27px;"></span>Home</a></li>
                <li id="news"><a href="market"><span class="a-btn-symbol"><img src="images/market.png" style="width:27px; height:27px;"></span>Market</a></li>
                <li id="about"><a href="report"><span class="a-btn-symbol"><img src="images/report.png" style="width:27px; height:27px;"></span>Report</a></li>
                <li id="services"><a href="tools"><span class="a-btn-symbol"><img src="images/tools.png" style="width:27px; height:27px;"></span>Tools</a></li>
                <li id="contact"><a href="analytics"><span class="a-btn-symbol"><img src="images/analytics.png" style="width:27px; height:27px;"></span>Analytics</a></li>
                <li id="contact"><a href="links"><span class="a-btn-symbol">K</span>Links</a></li>
                <li id="contact"><a href="help"><span class="a-btn-symbol"><img src="images/help.png" style="width:27px; height:27px;"></span>Help</a></li>
            </ul>
              </nav>
              </div>
                <div class="clr"></div>
                
                <div class="middle-header">
                <nav id="main-nav">
                    <ul>
                    <li>
                    <a title="Equity" class="href" target="_self" onClick="window.open('equity','targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,top=300,resizable=yes,width=1200,height=200')"><img src="images/equity.png" height="25" width="25" style="margin-top:5px;"></a>
                    <span></span>                    </li>
                    <li>
                    <a title="Derivative" class="href" target="_self" onClick="window.open('derivative','targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=300,width=1200,height=200')"><img src="images/Derivative.png" height="28" width="28" style="margin-top:5px;"></a>
                    <span></span>                    </li>
                    <li>
                    <a title="Ticker Data" class="href" target="_self" onClick="window.open('cnxnifty','targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=300,width=1200,height=200')"><img src="images/ticker-data.png" height="25" width="25" style="margin-top:5px;"></a>
                    <span></span>                    </li>
                    <li>
                    <a title="Market Picture" class="href" target="_self" onClick="window.open('marketpicture','targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=300,width=1200,height=200')"><img src="images/market-picture.png" height="25" width="25" style="margin-top:7px;"></a>
                    <span></span>                    </li>
                    <li>
                    <a title="Market Movement" class="href" target="_self" onClick="window.open('marketmovement','targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=300,width=1200,height=200')"><img src="images/market-movement.png" height="30" width="30" style="margin-top:5px;"></a>
                    <span></span>                    </li>
                    
                  </ul>
                 </nav>
                </div>
                <div style="width:100%; float:left;">
                	<div style="border-style:groove; border-width:1px;font-family:helvetica; font-size:13px;" width="80%">
<div ><select><option>NMCEX</option>

</select>
<select>
<option>-Select-</option><option>FUTURE</option>

</select>
<select id="prdid" name="prdid">
				 <option>-Select-</option>
				 <option value="ALUMINIUM_L">ALUMINIUM L</option>
                 <option value="ALUMINIUM_S">ALUMINIUM S</option>
                 <option value="BRCRUDE_OIL">BRCRUDE OIL</option>
                 <option value="COPPER_L">COPPER L</option>
                 <option value="COPPER_S">COPPER S</option>
                 <option value="CRUDE_OIL">CRUDE OIL</option>
                 <option value="GOLD_L">GOLD L</option>
                 <option value="GOLD_S">GOLD S</option>
                 <option value="LEAD_L">LEAD L</option>
                 <option value="LEAD_S">LEAD S</option>
                 <option value="NATURAL_GAS">NATURAL GAS</option>
                 <option value="SILVER_L">SILVER L</option>
                 <option value="SILVER_S">SILVER S</option>
                 <option value="ZINC_L">ZINC L</option>
                 <option value="ZINC_S">ZINC S</option>
                 <option value="NICKEL_L">NICKEL L</option>
                 <option value="NICKEL_S">NICKEL S</option></select>
<select id="timeid" name="timeid" onchange="callFunction();">
<option>-Select-</option>

<option value="30Aug2014" onclick="">30Aug2014</option>
<option value="30Sep2014" onclick="">30Sep2014</option>
</select>

<input type="text" value="Profit / Loss" size="15" disabled style="margin-left:20%; background:#006633; color:#FFFFFF;text-align: center;" id="profit" />
</div>
</div>
                </div>
          </div>

<!--Main Container--------------------------------------------------------------------------------------->          
<div  id="container" style="height:345px; overflow:scroll;" ><!--<img src="img/ncmx-logo2.png" align="middle" width="800" height="300" style=" margin-left:200px; margin-top:20px;"/>                                   class="easyui-datagrid"-->

<table id="tblDataGrid" class='list' cellspacing="0" cellpadding="0" border="0" width="300"  style="width:100%; border:thin groove;" singleSelect="true" iconCls="icon-save" url="data/datagrid_data.json" >
     <thead style="background:#CCCCCC;">
        <tr>
             <th>Symbol</th>
             <th id="insname"  >Instr. Id</th>	
		  <th>Series/Expiry</th>
		  <th>Bid Qty</th>
		  <th>Bid Rate</th>
		  <th>Ask Rate</th>
		  <th>Ask Qty</th>
		  <th>Net Change</th>
		  <th>Open</th>
		  <th>High</th>
		  <th>Low</th>
		  <th>Prev Close</th>
		  <th>LTP</th>
		  <th>% Change</th>
		  <th>Avg. Trade Price</th>
		  <th>DPR</th>
		  <th>Vol.in(Lacs)</th>				
		  <th>Trend</th>				
		  <th>Life Time High</th>
		  <th>Life Time Low</th>
        </tr>
    </thead>
     <tbody style="height:100%; overflow:scroll;"   width="100%" border="0" class="datagrid-btable" id="Heading">

    </tbody>
</table>
<script language="javascript">

var table = document.getElementsByTagName("table")[0];
var tbody = table.getElementsByTagName("tbody")[0];
var row = table.getElementsByTagName("tr")[0];

tbody.onclick = function (e) {
    e = e || window.event;
    var data = [];
    var target = e.srcElement || e.target;
    while (target && target.nodeName !== "TR") {
        target = target.parentNode;
		
    }
    if (target) {
	
        var cells = target.getElementsByTagName("td");
        for (var i = 0; i < cells.length; i++) {
           data.push(cells[i].innerHTML);
           var j=i+1;
		   var k=i+21;
		   if(j==1){
			   document.getElementById('symbol').value=(cells[i].innerHTML);
			   }
			    if(j==2){
			   document.getElementById('insname').value=(cells[i].innerHTML);
			   }
			    if(j==3){
					   document.getElementById('expdate').value=(cells[i].innerHTML);
					   }
			    if(j==5){
			   document.getElementById('price').value=(cells[i].innerHTML);
			   }
			    if(k==21){
			    	document.getElementById('ssymbol').value=(cells[i].innerHTML);
			    }
			    if(k==22){
			    	document.getElementById('sinsname').value=(cells[i].innerHTML);
			    }
			    if(k==23){
			    	document.getElementById('sexpdate').value=(cells[i].innerHTML);
			    }
			
			    if(k==26){
			    	document.getElementById('sprice').value=(cells[i].innerHTML);
			    }
		   
        }
    }
 
};

</script>


  
        <script type="text/javascript">
        $(function(){
       	    $("#tblDataGrid").dataTable();
       	  });
        </script>
        	<script>
       	var id,productid;
       	function callFunction(){
       		
       		id = document.getElementById('prdid').value;
       		
       		productid = document.getElementById('timeid').value;
       		var select = document.getElementById("timeid");
       		$('#timeid option[value!="0"]').remove();
       		
       		var option = document.createElement("option");
       		 
       		option.value ="";
               option.textContent ="-Select-";
               select.appendChild(option);
               var option1 = document.createElement("option");
       	     
       	     option1.value ="30Aug2014";
       	        option1.textContent ="30Aug2014";
       	        select.appendChild(option1);
       	        
       	        var option2 = document.createElement("option");
       		        
       	        option2.value ="30Sep2014";
       	        option2.textContent ="30Sep2014";
       	        select.appendChild(option2);
       	
       }

       		var socket = new SockJS("/ncmxtradeX/hs");
       		var stompClient = Stomp.over(socket);

       		function renderQuote(frame) {
       			
       			var Headings = JSON.parse(frame.body);
       		
       			for ( var i in Headings) {
       				var Heading = Headings[i];
       			var rows=document.all("Heading").rows.length;
               	var rowid = 'row'+rows;
               	updateRow(Heading);
       			
       			if(Heading['symbol'] == id && Heading['contentId'] == productid){
       				var a=findRow(id,productid,Heading);
       				if(a==0){
       				$('#Heading').append(
       						$('<tr id='+rowid+'>').append(
       								$('<td>').html(Heading.symbol),
    								$('<td>').html(Heading.instId),
    								$('<td>').html(Heading.contentId),
    								$('<td>').html(Heading.ask_Qty),
    								$('<td>').html(Heading.bid_Rate),
    								$('<td>').html(Heading.ask_Rate),
    								$('<td>').html(Heading.bid_Qty),
    								$('<td>').html(Heading.netChange),
    								$('<td>').html(Heading.open),
    								$('<td>').html(Heading.high),
    								$('<td>').html(Heading.low),
    								$('<td>').html(Heading.prev_Close),
    								$('<td>').html(Heading.ltp),
    								$('<td>').html(Heading.perChange),
    								$('<td>').html(Heading.atp),
    								$('<td>').html(Heading.dpr),
    								$('<td>').html(Heading.voll),
    								$('<td>').html(Heading.trend),
    								$('<td>').html(Heading.lth),
    								$('<td>').html(Heading.ltl)
       							)	
       						);
       				}
       			}
       			}
       		}
       				// Callback function to be called when stomp client is connected to server
       		var connectCallback = function() {
       			stompClient.subscribe('/topic/Heading', renderQuote);
       		};

       		// Callback function to be called when stomp client could not connect to server
       		var errorCallback = function(error) {
       			alert(error.headers.message);
       		};

       		// Connect to server via websocket
       		stompClient.connect("guest", "guest", connectCallback, errorCallback);

       		function findRow(id,productId,Heading){
       			var a=0;
       			
       			var table = document.getElementById("Heading");
       			for (var i = 0, row; row = table.rows[i]; i++) {
       					if(row.cells[0].innerHTML==id && row.cells[2].innerHTML==productId){
       					 row.cells[0].innerHTML=Heading.symbol;
						 	row.cells[1].innerHTML=Heading.instId;
							row.cells[2].innerHTML=Heading.contentId;
							row.cells[3].innerHTML=Heading.ask_Qty;
							row.cells[4].innerHTML=Heading.bid_Rate;
							row.cells[5].innerHTML=Heading.ask_Rate;
							row.cells[6].innerHTML=Heading.bid_Qty;
							row.cells[7].innerHTML=Heading.netChange;
							row.cells[8].innerHTML=Heading.open;
							row.cells[9].innerHTML=Heading.high;
							row.cells[10].innerHTML=Heading.low;
							row.cells[11].innerHTML=Heading.prev_Close;
							row.cells[12].innerHTML=Heading.ltp;
							row.cells[13].innerHTML=Heading.perChange;
							row.cells[14].innerHTML=Heading.atp;
							row.cells[15].innerHTML=Heading.dpr;
							row.cells[16].innerHTML=Heading.voll;
							row.cells[17].innerHTML=Heading.trend;
							row.cells[18].innerHTML=Heading.lth;
							row.cells[19].innerHTML=Heading.ltl; 
       						a=1;
       						break;
       					}			     
       			}
       			return a;
       		}
       		
       		function updateRow(Heading){
       			var table = document.getElementById("Heading");
       			for (var i = 0, row; row = table.rows[i]; i++) {
       			  if(row.cells[0].innerHTML==Heading.symbol && row.cells[2].innerHTML==Heading.contentId){
       				 row.cells[0].innerHTML=Heading.symbol;
					 	row.cells[1].innerHTML=Heading.instId;
						row.cells[2].innerHTML=Heading.contentId;
						row.cells[3].innerHTML=Heading.ask_Qty;
						row.cells[4].innerHTML=Heading.bid_Rate;
						row.cells[5].innerHTML=Heading.ask_Rate;
						row.cells[6].innerHTML=Heading.bid_Qty;
						row.cells[7].innerHTML=Heading.netChange;
						row.cells[8].innerHTML=Heading.open;
						row.cells[9].innerHTML=Heading.high;
						row.cells[10].innerHTML=Heading.low;
						row.cells[11].innerHTML=Heading.prev_Close;
						row.cells[12].innerHTML=Heading.ltp;
						row.cells[13].innerHTML=Heading.perChange;
						row.cells[14].innerHTML=Heading.atp;
						row.cells[15].innerHTML=Heading.dpr;
						row.cells[16].innerHTML=Heading.voll;
						row.cells[17].innerHTML=Heading.trend;
						row.cells[18].innerHTML=Heading.lth;
						row.cells[19].innerHTML=Heading.ltl; 
       			  } 
       			}
       			
       		}
       		
       	</script> 

   
</div>

<!--FOOTER---------------------------------------------------------------------------------------->          
  <%@include file="footer.jsp" %>

</body>
</html>